/*
 * Copyright 2008 Carnegie Mellon University
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, 
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

function loadTopicList( action ) {
  var list = $('topicList');
  
  initList(list);
  $('poolList').disabled=true;
   
  var param = eval('$H({"action": "'+action+'"})').toQueryString();//, "poolId": "'+poolId+'"
  var json = sync(param);
  topics = json.topics;
  resetList(list);

   for (var i = 0; i < topics.length; i++) {
     var done = "";//(json.topics[i].done==1)?"[x] ":"";
     var opt = document.createElement("option");
     var id = topics[i].externalId;
     opt.id = "topic"+id;
     opt.selected = ( lastTopicId == id );
     opt.value = id;
     var qTrg = topics[i].questionTrg;
     var type = topics[i].type;
     type = type?(" ["+type+"] "):"  ";
     var str = document.createTextNode(done+id+type+qTrg);
     opt.appendChild(str);
     list.appendChild( opt );
   }
   
   $('poolList').disabled=false;
}

function loadPoolList(action) {
  var list = $('poolList');
    $('topicList').disabled=true;
    initList(list);
  
    var param = eval('$H({"action": "'+action+'"})').toQueryString();
    var json = sync(param);
    resetList(list);
  for (var i = 0; i < json.pools.length; i++) {
    var done = "";
      var opt = document.createElement("option");
    opt.value = json.pools[i].pool_id;
    var id = json.pools[i].pool_id;
    opt.id = "pool"+id;
    opt.value = id;
    opt.selected = ( lastPoolId == id );
    var str = document.createTextNode(done+json.pools[i].pool_name);
    opt.appendChild(str);
    list.appendChild( opt );
  }
  $('topicList').disabled=false;
}

